package com.lihui.exercises;

import com.lihui.dao.ClassesDao;
import com.lihui.dao.StudentDao;
import com.lihui.model.Classes;
import com.lihui.model.Student;

import java.text.MessageFormat;
import java.util.List;
import java.util.Scanner;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2022/12/29  15:36
 */
public class Exe_03 {
    public static void main(String[] args) {
        while(true){
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入要查询班级名称：");
            String  classesName = scanner.nextLine();
            ClassesDao classesDao = new ClassesDao();
            Classes classes = classesDao.selectByName(classesName);
            if(classes == null){
                System.out.println("要查询的班级不存在" + classesName);
                return;
            }

            StudentDao studentDao = new StudentDao();
            List<Student> students = studentDao.selectById(classes.getId());
            if(students == null || students.size() == 0){
                System.out.println("没有找到对应班级学生信息 --->" + classesName);
                return;
            }
            for (Student student:students) {
                String info = MessageFormat.format("编号: {0}\t| 学号: {1}\t| 姓名: {2}\t | " +
                                "邮箱: {3}\t| 班级编号: {4}", student.getId(), student.getSn(), student.getName(),
                        student.getMail(), student.getClassesId());
                System.out.println(info);
            }
        }
    }
}
